package com.android.SQL;


import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.View;

import com.android.R;
import com.android.bean.DeliveryAdr;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    View view;
    private static final String SQL_CREATE_ENTRIES =
            "CREATE TABLE " + DeliveryAdr.DeliveryEntry.TABLE_NAME + " (" +
                    DeliveryAdr.DeliveryEntry._ID + " INTEGER PRIMARY KEY, " +
                    DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_NAME + " VARCHAR(200), " +
                    DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_TELE + " VARCHAR(200), " +
                    DeliveryAdr.DeliveryEntry.COLUMN_DETAIL_ADR + " VARCHAR(100), " +
                    DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW  + " VARCHAR(100) " +
                    ")" ;

    private static final String SQL_DELETE_ENTRIES =
            "DROP TABLE IF EXISTS " + DeliveryAdr.DeliveryEntry.TABLE_NAME;

    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "deliverys.db";

    private Context mContext;
    public MySQLiteOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES);


    }
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase,
                          int oldVersion, int newVersion) {
        sqLiteDatabase.execSQL(SQL_DELETE_ENTRIES);
        onCreate(sqLiteDatabase);
    }

//    private void initDb(SQLiteDatabase sqLiteDatabase) {
//
//        Resources resources = mContext.getResources();
//        String[] titles = resources.getStringArray(R.array.titles);
//        String[] authors = resources.getStringArray(R.array.authors);
//        String[] contents = resources.getStringArray(R.array.contents);
//        TypedArray images = resources.obtainTypedArray(R.array.images);
//
//        int length = 0;
//        length = Math.min(titles.length, authors.length);
//        length = Math.min(length, contents.length);
//        length = Math.min(length, images.length());
//
//        for (int i = 0; i < length; i++) {
//            ContentValues values = new ContentValues();
//            values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_NAME ,
//                    titles[i]);
//            values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_TELE,
//                    authors[i]);
//            values.put(DeliveryAdr.DeliveryEntry.COLUMN_DETAIL_ADR ,
//                    contents[i]);
//            values.put(DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW ,
//                    images.getString(i));
//
//            long r = sqLiteDatabase.insert(
//                    DeliveryAdr.DeliveryEntry.TABLE_NAME,
//                    null,
//                    values);
//        }
//    }
}
